Java Persistence API
   HOME

TheInfoList



OR:

Jakarta Persistence (JPA; formerly Java Persistence API) is a
Jakarta EE Jakarta EE, formerly Java Platform, Enterprise Edition (Java EE) and Java 2 Platform, Enterprise Edition (J2EE), is a set of specifications, extending Java SE with specifications for enterprise features such as distributed computing and web serv ...
application programming interface An application programming interface (API) is a way for two or more computer programs to communicate with each other. It is a type of software interface, offering a service to other pieces of software. A document or standard that describes how t ...
specification that describes the management of
relational data Relational may refer to: Business * Relational capital, the value inherent in a company's relationships with its customers, vendors, and other important constituencies * Relational contract, a contract whose effect is based upon a relationship o ...
in enterprise
Java Java (; id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 151.6 million people, Java is the world's List ...
applications. Persistence in this context covers three areas: * The
API An application programming interface (API) is a way for two or more computer programs to communicate with each other. It is a type of software interface, offering a service to other pieces of software. A document or standard that describes how ...
itself, defined in the jakarta.persistence
/code> package ( for Jakarta EE 8 and below) * The Jakarta Persistence Query Language (JPQL; formerly Java Persistence Query Language) * Object/relational metadata The
reference implementation In the software development process, a reference implementation (or, less frequently, sample implementation or model implementation) is a program that implements all requirements from a corresponding specification. The reference implementation o ...
for JPA is
EclipseLink EclipseLink is the open source Eclipse Persistence Services Project from the Eclipse Foundation. The software provides an extensible framework that allows Java developers to interact with various data services, including databases, web services, ...
.


History

The final release date of the JPA 1.0 specification was 11 May 2006 as part of
Java Community Process The Java Community Process (JCP), established in 1998, is a formalized mechanism that allows interested parties to develop standard technical specifications for Java technology. Anyone can become a JCP Member by filling a form available at thJCP w ...
JSR 220. The JPA 2.0 specification was released 10 December 2009 (the Java EE 6 platform requires JPA 2.0). The JPA 2.1 specification was released 22 April 2013 (the Java EE 7 platform requires JPA 2.1). The JPA 2.2 specification was released in the summer of 2017. The JPA 3.1 specification, the latest version, was released in the spring of 2022 as part of Jakarta EE 10.


Entities

A persistence
entity An entity is something that exists as itself, as a subject or as an object, actually or potentially, concretely or abstractly, physically or not. It need not be of material existence. In particular, abstractions and legal fictions are usually ...
is a lightweight
Java class A Java class file is a file (with the filename extension) containing Java bytecode that can be executed on the Java Virtual Machine (JVM). A Java class file is usually produced by a Java compiler from Java programming language source files ( fi ...
with its state typically persisted to a
table Table may refer to: * Table (furniture), a piece of furniture with a flat surface and one or more legs * Table (landform), a flat area of land * Table (information), a data arrangement with rows and columns * Table (database), how the table data ...
in a
relational database A relational database is a (most commonly digital) database based on the relational model of data, as proposed by E. F. Codd in 1970. A system used to maintain relational databases is a relational database management system (RDBMS). Many relatio ...
. Instances of such an entity correspond to individual rows in the table. Entities typically have relationships with other entities, and these relationships are expressed through object/relational mapping (ORM) metadata. This metadata may be specified directly in the entity class file by using
annotations An annotation is extra information associated with a particular point in a document or other piece of information. It can be a note that includes a comment or explanation. Annotations are sometimes presented in the margin of book pages. For anno ...
or in a separate
XML Extensible Markup Language (XML) is a markup language and file format for storing, transmitting, and reconstructing arbitrary data. It defines a set of rules for encoding documents in a format that is both human-readable and machine-readable. T ...
descriptor file distributed with the application.


Example

An example entity class with ORM metadata declared using annotations (import statements and setters/getters are omitted for simplicity). @Entity public class Person The @Entity annotation declares that the class represents an entity. @Id declares the attribute which acts as the
primary key In the relational model of databases, a primary key is a ''specific choice'' of a ''minimal'' set of attributes (Column (database), columns) that uniquely specify a tuple (Row (database), row) in a Relation (database), relation (Table (database), t ...
of the entity. Additional annotations may be used to declare additional metadata (for example changing the default table name in the @Table annotation), or to create associations between entities.


Query Language

The Jakarta Persistence Query Language (JPQL; formerly Java Persistence Query Language) makes queries against entities stored in a relational database. Queries resemble SQL queries in syntax but operate against entity objects rather than directly with database tables.


Motivation

Prior to the introduction of EJB 3.0 specification, many enterprise Java developers used lightweight persistent objects provided by either persistence frameworks (such as
Hibernate Hibernation is a state of minimal activity and metabolic depression undergone by some animal species. Hibernation is a seasonal heterothermy characterized by low body-temperature, slow breathing and heart-rate, and low metabolic rate. It most ...
) or
data access object In software, a data access object (DAO) is a pattern that provides an abstract interface to some type of database or other persistence mechanism. By mapping application calls to the persistence layer, the DAO provides data operations without expo ...
s (DAO) instead of by using entity beans. This is because entity beans, in previous EJB specifications, called for much complicated code and imposed a heavy resource footprint, and they could be used only on Java EE application servers because of interconnections and dependencies in the source code between beans and DAO objects or persistence frameworks. Thus, many of the features originally presented in third-party persistence frameworks were incorporated into the Java Persistence API, and projects such as
Hibernate Hibernation is a state of minimal activity and metabolic depression undergone by some animal species. Hibernation is a seasonal heterothermy characterized by low body-temperature, slow breathing and heart-rate, and low metabolic rate. It most ...
and TopLink Essentials have become implementations of the Java Persistence API specification.


Related technologies


Enterprise Beans

The EJB 3.0 specification (itself part of the Java EE 5 platform) included a definition of the Java Persistence API. However, developers do not need an EJB container or a Java EE application server to run applications that use this persistence API. Future versions of the Java Persistence API will be defined in a separate JSR and specification rather than in the EJB JSR/specification. The Java Persistence API replaces the persistence solution of EJB 2.0 CMP (Container-Managed Persistence).


Java Data Objects API

The Java Persistence API was developed in part to unify the Java Data Objects API and the EJB 2.0 Container Managed Persistence (CMP) API. Most products supporting each of the two APIs support the Java Persistence API. The Java Persistence API specifies persistence only for
relational database management system A relational database is a (most commonly digital) database based on the relational model of data, as proposed by E. F. Codd in 1970. A system used to maintain relational databases is a relational database management system (RDBMS). Many relatio ...
s by focusing on object-relational mapping (ORM). Some JPA providers support other database models, though this is outside the scope of JPA's design. The introduction section of the JPA specification states: "The technical objective of this work is to provide an object/relational mapping facility for the Java application developer using a Java domain model to manage a relational database." The
Java Data Objects Java Data Objects (JDO) is a specification of Java object persistence. One of its features is a transparency of the persistence services to the domain model. JDO persistent objects are ordinary Java programming language classes ( POJOs); there ...
specification supports ORM as well as persistence to other types of database models, for example,
flat file database A flat-file database is a database stored in a file called a flat file. Records follow a uniform format, and there are no structures for indexing or recognizing relationships between records. The file is simple. A flat file can be a plain ...
s and
NoSQL A NoSQL (originally referring to "non- SQL" or "non-relational") database provides a mechanism for storage and retrieval of data that is modeled in means other than the tabular relations used in relational databases. Such databases have existed ...
databases, including
document database A document-oriented database, or document store, is a computer program and data storage system designed for storing, retrieving and managing document-oriented information, also known as semi-structured data. Document-oriented databases are one ...
s,
graph database A graph database (GDB) is a database that uses graph structures for semantic queries with nodes, edges, and properties to represent and store data. A key concept of the system is the ''graph'' (or ''edge'' or ''relationship''). The graph relat ...
s any many other datastores.


Service Data Object API

The designers of the Java Persistence API aimed to provide for relational persistence, with many of the key areas taken from object-relational mapping tools such as
Hibernate Hibernation is a state of minimal activity and metabolic depression undergone by some animal species. Hibernation is a seasonal heterothermy characterized by low body-temperature, slow breathing and heart-rate, and low metabolic rate. It most ...
and
TopLink Oracle TopLink is a mapping and persistence framework for Java developers. TopLink is produced by Oracle and is a part of Oracle's OracleAS, WebLogic, and OC4J servers. It is an object-persistence and object-transformation framework. TopLink p ...
. Java Persistence API improved on and replaced EJB 2.0, evidenced by its inclusion in EJB 3.0. The Service Data Objects (SDO) API (JSR 235) has a very different objective to that of the Java Persistence API and is considered complementary. The SDO API is designed for
service-oriented architecture In software engineering, service-oriented architecture (SOA) is an architectural style that focuses on discrete services instead of a monolithic design. By consequence, it is also applied in the field of software design where services are provide ...
s, multiple data formats rather than only relational data and multiple programming languages. The
Java Community Process The Java Community Process (JCP), established in 1998, is a formalized mechanism that allows interested parties to develop standard technical specifications for Java technology. Anyone can become a JCP Member by filling a form available at thJCP w ...
manages the Java version of the SDO API; the
C++ C++ (pronounced "C plus plus") is a high-level general-purpose programming language created by Danish computer scientist Bjarne Stroustrup as an extension of the C programming language, or "C with Classes". The language has expanded significan ...
version of the SDO API is managed via
OASIS In ecology, an oasis (; ) is a fertile area of a desert or semi-desert environment'ksar''with its surrounding feeding source, the palm grove, within a relational and circulatory nomadic system.” The location of oases has been of critical imp ...
.


Hibernate

Hibernate, founded by Gavin King, provides an
open source Open source is source code that is made freely available for possible modification and redistribution. Products include permission to use the source code, design documents, or content of the product. The open-source model is a decentralized sof ...
object-relational mapping framework for
Java Java (; id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 151.6 million people, Java is the world's List ...
. Versions 3.2 and later provide an implementation for the Java Persistence API. King represented
JBoss WildFly, formerly known as JBoss AS, or simply JBoss, is an application server written by JBoss, now developed by Red Hat. WildFly is written in Java and implements the Java Platform, Enterprise Edition (Java EE) specification. It runs on multip ...
on JSR 220, the JCP expert group charged with developing JPA. This led to ongoing controversy and speculation surrounding the relationship between JPA and Hibernate.
Sun Microsystems Sun Microsystems, Inc. (Sun for short) was an American technology company that sold computers, computer components, software, and information technology services and created the Java programming language, the Solaris operating system, ZFS, the ...
stated that ideas came from several frameworks, including Hibernate and
Java Data Objects Java Data Objects (JDO) is a specification of Java object persistence. One of its features is a transparency of the persistence services to the domain model. JDO persistent objects are ordinary Java programming language classes ( POJOs); there ...
.


Spring Data JPA

The Spring Data JPA is an implementation of the repository abstraction that is a key building block of
domain-driven design Domain-driven design (DDD) is a major software design approach, focusing on modeling software to match a domain according to input from that domain's experts. Under domain-driven design, the structure and language of software code (class name ...
based on the Java application framework
Spring Spring(s) may refer to: Common uses * Spring (season) Spring, also known as springtime, is one of the four temperate seasons, succeeding winter and preceding summer. There are various technical definitions of spring, but local usage of ...
. It transparently supports all available JPA implementations and supports
CRUD In computer programming, create, read, update, and delete (CRUD) are the four basic operations of persistent storage. CRUD is also sometimes used to describe user interface conventions that facilitate viewing, searching, and changing information u ...
operations as well as the convenient execution of database queries.


Version history


JPA 2.0

Development of a new version of JPA 2.0 was started in July 2007 in the Java Community Process as JSR 317. JPA 2.0 was approved as final on 10 December 2009. The focus of JPA 2.0 was to address features that were present in some of the popular ORM vendors but could not gain consensus approval for JPA 1.0. Main features included were: * Expanded object-relational mapping functionality ** Support for collections of embedded objects, linked in the ORM with a many-to-one relationship ** Ordered lists ** Combinations of access types * A criteria query API * Standardization of
SQL Hints In various SQL implementations, a hint is an addition to the SQL standard that instructs the database engine on how to execute the query. For example, a hint may tell the engine to use or not to use an index (even if the query optimizer would decid ...
* Standardization of additional metadata to support DDL generation * Support for validation * Shared object cache support. Vendors supporting JPA 2.0: *
Batoo JPA Batoo JPA is an implementation of Java Persistence API version 1.0 and 2.0. It is created as a response to the assumption that the current JPA implementations are quite heavy implementations that require large CPU resources during execution therefo ...
*
DataNucleus DataNucleus (formerly known as Java Persistent Objects JPOX) is an open source project (under the Apache 2 license) which provides software products around data management in Java. The DataNucleus project started in 2008 (the JPOX project started ...
(formerly JPOX) *
EclipseLink EclipseLink is the open source Eclipse Persistence Services Project from the Eclipse Foundation. The software provides an extensible framework that allows Java developers to interact with various data services, including databases, web services, ...
(formerly Oracle TopLink) * IBM, for
WebSphere Application Server WebSphere Application Server (WAS) is a software product that performs the role of a web application server. More specifically, it is a software framework and middleware that hosts Java-based web applications. It is the flagship product with ...
*
JBoss WildFly, formerly known as JBoss AS, or simply JBoss, is an application server written by JBoss, now developed by Red Hat. WildFly is written in Java and implements the Java Platform, Enterprise Edition (Java EE) specification. It runs on multip ...
with
Hibernate Hibernation is a state of minimal activity and metabolic depression undergone by some animal species. Hibernation is a seasonal heterothermy characterized by low body-temperature, slow breathing and heart-rate, and low metabolic rate. It most ...
*
ObjectDB ObjectDB is an object database for Java. It can be used in client-server mode and in embedded (in process) mode. Unlike other object databases, ObjectDB does not provide its own proprietary API. Accordingly, working with ObjectDB requires using ...
* OpenJPA *
OrientDB OrientDB is an open source NoSQL database management system written in Java. It is a Multi-model database, supporting graph, document, key/value, and object models, but the relationships are managed as in graph databases with direct connections ...
*
Versant Corporation Versant Object Database (VOD) is an object database software product developed by Versant Corporation. The Versant Object Database enables developers using object oriented languages to transactionally store their information by allowing the r ...
JPA (
object database An object database or object-oriented database is a database management system in which information is represented in the form of objects as used in object-oriented programming. Object databases are different from relational databases which a ...
)


JPA 2.1

Development of JPA version 2.1 began in July 2011 as JSR 338. JPA 2.1 was approved as final on 22 May 2013. Main features included were: * Converters, which allow custom code conversions between database and object types * Criteria update/delete to allow bulk updates and deletes through the Criteria API * Entity graphs for partial or specified fetching or merging of objects. * JPQL/Criteria enhancements such as arithmetic subqueries, generic database functions, join ON clause and the TREAT option. * Schema generation * Support for stored procedures Vendors supporting JPA 2.1: *
DataNucleus DataNucleus (formerly known as Java Persistent Objects JPOX) is an open source project (under the Apache 2 license) which provides software products around data management in Java. The DataNucleus project started in 2008 (the JPOX project started ...
*
EclipseLink EclipseLink is the open source Eclipse Persistence Services Project from the Eclipse Foundation. The software provides an extensible framework that allows Java developers to interact with various data services, including databases, web services, ...
*
Hibernate Hibernation is a state of minimal activity and metabolic depression undergone by some animal species. Hibernation is a seasonal heterothermy characterized by low body-temperature, slow breathing and heart-rate, and low metabolic rate. It most ...
* OpenJPA (from version 2.2.0)


JPA 2.2

Development of JPA 2.2, a maintenance release, began in 2017 under JSR 338. The maintenance review was approved on 19 June 2017. Main features included were: * The addition of @Repeatable to all relevant annotations * Support for JPA annotations to be used in metaannotations * Streaming for query results * The ability for AttributeConverters to be CDI-injectable * Support for Java 8 date and time types Vendors supporting JPA 2.2: *
DataNucleus DataNucleus (formerly known as Java Persistent Objects JPOX) is an open source project (under the Apache 2 license) which provides software products around data management in Java. The DataNucleus project started in 2008 (the JPOX project started ...
(from version 5.1) *
EclipseLink EclipseLink is the open source Eclipse Persistence Services Project from the Eclipse Foundation. The software provides an extensible framework that allows Java developers to interact with various data services, including databases, web services, ...
(from version 2.7) *
Hibernate Hibernation is a state of minimal activity and metabolic depression undergone by some animal species. Hibernation is a seasonal heterothermy characterized by low body-temperature, slow breathing and heart-rate, and low metabolic rate. It most ...
(from version 5.3) * OpenJPA (from version 3.0.0)


Jakarta Persistence 3.0

The JPA was renamed as Jakarta Persistence in 2019 and version 3.0 was released in 2020. This included the renaming of packages and properties from javax.persistence to jakarta.persistence. Vendors supporting Jakarta Persistence 3.0: *
DataNucleus DataNucleus (formerly known as Java Persistent Objects JPOX) is an open source project (under the Apache 2 license) which provides software products around data management in Java. The DataNucleus project started in 2008 (the JPOX project started ...
(from version 6.0) *
EclipseLink EclipseLink is the open source Eclipse Persistence Services Project from the Eclipse Foundation. The software provides an extensible framework that allows Java developers to interact with various data services, including databases, web services, ...
(from version 3.0) *
Hibernate Hibernation is a state of minimal activity and metabolic depression undergone by some animal species. Hibernation is a seasonal heterothermy characterized by low body-temperature, slow breathing and heart-rate, and low metabolic rate. It most ...
(from version 5.5)


Jakarta Persistence 3.1

Version 3.1 was released in 2022. It is part of Jakarta EE 10, and thus requires at least Java 11 to run. Vendors supporting Jakarta Persistence 3.1: *
DataNucleus DataNucleus (formerly known as Java Persistent Objects JPOX) is an open source project (under the Apache 2 license) which provides software products around data management in Java. The DataNucleus project started in 2008 (the JPOX project started ...
(from version 6.0) *
EclipseLink EclipseLink is the open source Eclipse Persistence Services Project from the Eclipse Foundation. The software provides an extensible framework that allows Java developers to interact with various data services, including databases, web services, ...
(from version 4.0) *
Hibernate Hibernation is a state of minimal activity and metabolic depression undergone by some animal species. Hibernation is a seasonal heterothermy characterized by low body-temperature, slow breathing and heart-rate, and low metabolic rate. It most ...
(from version 6.0)


See also

* .NET Persistence API (NPA) *
JDBC Java Database Connectivity (JDBC) is an application programming interface (API) for the programming language Java, which defines how a client may access a database. It is a Java-based data access technology used for Java database connectivity. I ...
*
MyBatis MyBatis is a Java persistence framework that couples objects with stored procedures or SQL statements using an XML descriptor or annotations. MyBatis is free software that is distributed under the Apache License 2.0. MyBatis is a fork of iBATI ...
*
pureQuery Db2 is a family of data management products, including database servers, developed by IBM. It initially supported the relational model, but was extended to support object–relational features and non-relational structures like JSON a ...
*
SAP NetWeaver Application Server SAP NetWeaver Application Server or SAP Web Application Server is a component of SAP NetWeaver which works as a web application server for SAP products. All ABAP application servers including the message server represent the application layer of th ...
* XQJ


References


External links


General info

*
Documentation for the final version of the EJB3 spec (called JSR220)

GlassFish's Persistence page



Tutorials











{{DEFAULTSORT:Jakarta Persistence Java APIs Java enterprise platform Java specification requests Object-relational mapping Persistence